//Get current appliactions path and exe filename.
//By DreamVB
#include <iostream>
#include <Windows.h>

using namespace std;
using std::cout;
using std::endl;

#define BUFFER_SIZE 2048

string GetAppExeName(){
	wstring Ret;
	string s0 = "";
	int pos = 0;

	TCHAR fName[MAX_PATH];
	//Get full path and exe name.
	GetModuleFileName(NULL, fName, MAX_PATH);
	//Get wide string
	Ret = fName;
	//Get from from wide string
	s0 = string(Ret.begin(), Ret.end());
	//Locate last backslash
	pos = s0.find_last_of("\\");

	if (pos != string::npos){
		return s0.substr(pos + 1);
	}
	
	return s0;
}

string AppPath(){
	char AppPath[MAX_PATH];
	//Get current folder app is running
	GetCurrentDirectoryA(MAX_PATH, AppPath);
	//Append backslash if needed.
	if (AppPath[strlen(AppPath) - 1] != '\\'){
		strcat(AppPath, "\\");
	}
	//Return path.
	return AppPath;
}

int main(int argc, char *argv[]){
	//Show current path
	cout << "App Path is :" << endl;
	cout << AppPath().c_str() << endl;
	//Show exe name
	cout << "Exe Name: " << GetAppExeName().c_str() << endl;

	system("pause");
	return 0;
}